-- All floating-point math removed

-- Function: Pursuit & Wall Following

function PW(x, y, Speed)
	forward(y, 3*Speed/4)
	if sonarR < (3*sonarRange/4) then
		forward(x, 3*Speed/4)
		forward(y, Speed)
	end
	if sonarL > (3*sonarRange/4) then
		repeat
			forward(x, Speed)
			forward(y, 3*Speed/4)
		until sonarL > 45 or sonarR > 45
	end

end

function lightTest(sonarF, sonarR, sonarL, Speed, sonarRange)

-- LightFinding & Object Avoidance
	stop(A)
	stop(B)
	if sonarF < sonarRange then
		backward(A, Speed)
		backward(B, Speed)
	elseif sonarR < sonarRange then
		resetRotationCount(B)
		repeat
		forward(B, 3*Speed/4) 
		until rotationCounts(B) > 365
		forward(A, Speed)
		forward(B, Speed)
	elseif sonarL < sonarRange then
		resetRotationCount(A)
		repeat
			forward(A) 
		until rotationCounts(A) > 365
		forward(A, Speed)
		forward(B, Speed)
	end
end

-- -------------------------------------------
	-- Initializing Sensors

	sonarF = sonarReading(1)
	sonarL = sonarReading(2)
	sonarR = sonarReading(3)
	light = passiveLightReading(4)
	sleep(200)
-- -------------------------------------------

-- variables
lightMax = 70
sonarRange = 90
Speed = 50

repeat
	write("starting loop")
	forward(A, Speed)
	forward(B, Speed)
	sleep(500)
	write("second stage")
	stop(B)
	backward(B, 20)
	sleep(500)
	sleep(500)
	write("third stage")
	forward(B, Speed)
	sleep(900)
	write("fourth stage")
	forward(A, 8)
	sleep(900)
	write("fifth stage")
	forward(A, Speed)
	write("end of loop")
until isPressed(ESCAPE)


